<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        div {
            margin: 200px;
        }

        span {
            display: inline-block;
            width: 80px;
            height: 40px;
            background-color: #333;
            font-size: 20px;
            color: #fff;
            text-align: center;
            line-height: 40px;
        }
    </style>
</head>

<body>
    <div>
        <span class="day">天</span>
        <span class="hour">时</span>
        <span class="minute">分</span>
        <span class="second">秒</span>
    </div>

    <script>
        // 获取span元素
        var day = document.querySelector('.day');
        var hour = document.querySelector('.hour');
        var minute = document.querySelector('.minute');
        var second = document.querySelector('.second');

        // 输入截止时间
        var inputTime = new Date('2020-10-1 23:59:59');

        // 因为定时器最开始有延迟，提前调用一次倒计时
        countDown();
        // 每隔1秒调用一次倒计时函数
        var count = setInterval(countDown, 1000);

        // 倒计时函数
        function countDown() {
            // 获取当前时间
            var currentTime = Date.now();
            // 把输入时间转化成毫秒值，可省略
            // var inputTime = input.valueOf();
            // 把剩余毫秒值转化成秒
            var count = (inputTime - currentTime) / 1000;

            var d = parseInt(count / 60 / 60 / 24);
            d = d < 10 ? '0' + d : d;
            day.innerHTML = d + '天';

            var h = parseInt(count / 60 / 60 % 24);
            h = h < 10 ? '0' + h : h;
            hour.innerHTML = h + '时';

            var m = parseInt(count / 60 % 60);
            m = m < 10 ? '0' + m : m;
            minute.innerHTML = m + '分';

            var s = parseInt(count % 60);
            s = s < 10 ? '0' + s : s;
            second.innerHTML = s + '秒';

            // return '还剩' + d + '天' + h + '时' + m + '分' + s + '秒';

        }
    </script>
</body>

</html>